<template>
   <div class="article-lists">
       <el-card class="!border-none" shadow="never">
         <el-form ref="formRef" :inline="true" :model="queryParams" class="mb-[-16px]">
           <el-form-item label="企业名称">
             <el-input
               v-model="queryParams.title"
               class="w-[280px]"
               clearable
               @keyup.enter="resetPage"
             />
           </el-form-item>
   
   
           <el-form-item>
             <el-button type="primary" @click="resetPage">查询</el-button>
             <el-button @click="resetParams">重置</el-button>
           </el-form-item>
         </el-form>
       </el-card>
       <el-card class="!border-none mt-4" shadow="never">
         <div>
           <router-link
             v-perms="['enterprise.enterprise']"
             :to="{
                           path: getRoutePath('enterprise.enterprise')
                       }"
           >
             <el-button class="mb-4" type="primary">
               <template #icon>
                 <icon name="el-icon-Plus" />
               </template>
               新增企业
             </el-button>
           </router-link>
         </div>
         <el-table :data="pager.lists" size="large">
           <el-table-column label="ID" min-width="80" prop="id" />
           <el-table-column label="门店照片" min-width="100">
             <template #default="{ row }">
            <!--  <image-contain
                 v-if="row.trademark"
                 :height="45"
                 :preview-src-list="[row.trademark]"
                 :src="row.trademark"
                 :width="60"
                 fit="contain"
                 preview-teleported
               /> -->
			   <block v-for="item in row.trademark" style="">
				     <image-contain
						style="display: inline-block;"
				       :height="45"
				       :preview-src-list="[item.img]"
				       :src="item.img"
				       :width="60"
				       fit="contain"
				       preview-teleported
				     />
			   </block>
			
             </template>
           </el-table-column>
   		<el-table-column label="企业类型" min-width="100">
   		  <template #default="{ row }">
   		    <div v-if="row.leixing=='0'">小微企业</div>
   			<div v-if="row.leixing=='1'">一般纳税人</div>
   		  </template>
   		</el-table-column>
           <el-table-column
             label="企业介绍"
             min-width="160"
             prop="introduce"
             show-tooltip-when-overflow
           />
   		<el-table-column label="企业名称" min-width="120" prop="name" />
           <el-table-column label="联系人" min-width="100" prop="contacts" />
   		<el-table-column label="联系电话" min-width="120" prop="phone" />
   		<el-table-column label="联系地址" min-width="120" prop="address" />
           <!--        <el-table-column label="浏览量" prop="click" min-width="100" />-->
           <!--        <el-table-column label="状态" min-width="100">
                     <template #default="{ row }">
                       <el-switch
                         v-perms="['article.article/updateStatus']"
                         v-model="row.is_show"
                         :active-value="1"
                         :inactive-value="0"
                         @change="changeStatus($event, row.id)"
                       />
                     </template>
                   </el-table-column>-->
           <el-table-column label="排序" min-width="100" prop="sort" />
           <!--        <el-table-column label="发布时间" prop="create_time" min-width="120" />-->
           <el-table-column label="操作" width="120" fixed="right">
             <template #default="{ row }">
               <el-button
                 v-perms="[ 'enterprise.enterprise']"
                 type="primary"
                 link
               >
                 <router-link
                   :to="{
                                       path: getRoutePath('enterprise.enterprise'),
                                       query: {
                                           id: row.id
                                       }
                                   }"
                 >
                   编辑
                 </router-link>
               </el-button>
               <el-button
                 v-perms="['article.article/delete']"
                 type="danger"
                 link
                 @click="handleDelete(row.id)"
               >
                 删除
               </el-button>
             </template>
           </el-table-column>
         </el-table>
  <div class="flex justify-end mt-4">
      <pagination v-model="pager" @change="getLists" />
  </div>
       </el-card>
     </div>
</template>
<script lang="ts" setup name="enterpriselist">
import { enterpriselist, enterpriseDelete, articleStatus, articleCateAll, batchDelete1,batchPass1,batchNotpassed1 } from '@/api/article'
import { useDictOptions } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/qiye'
import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'
const queryParams = reactive({
    title: '',
    cid: '',
    start: ''
})



const multipleSelection = ref([])
const idArr=ref([])
const handleSelectionChange = (val) => {
  multipleSelection.value = val
   idArr.value=[]
   multipleSelection.value.forEach(item=>{
	   idArr.value.push(item.id)
   })
   
  console.log(multipleSelection.value,'multipleSelection.value');
  console.log(idArr.value,'idArr.value');
}

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: enterpriselist,
    params: queryParams
})

const { optionsData } = useDictOptions<{
    article_cate: any[]
}>({
    article_cate: {
        api: articleCateAll
    }
})

const changeStatus = async (start: any, id: number) => {
    try {
        await articleStatus({ id, start })
        getLists()
    } catch (error) {
        getLists()
    }
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await enterpriseDelete({ id })
    getLists()
}

onActivated(() => {
    getLists()
})

getLists()
// 批量删除
const batchDeleteFn=async()=>{
	let idA=idArr.value
	let data=await batchDelete1({
		idA
	})
	getLists()
}

// 批量审核通过
const batchPassFn=async()=>{
	let idA=idArr.value
	let data=await batchPass1({
		idA
	})
	getLists()
}

// 批量审核不通过
const batchNotpassedFn=async()=>{
	let idA=idArr.value
	let data=await batchNotpassed1({
		idA
	})
	getLists()
}
</script>
